﻿using MaterialDemo.DataEntity;
using MaterialDemo.IService;
using MaterialDemo.IService.ILogin;
using MaterialDemo.Model.UserDTO;
using MaterialDemo.Utility;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using System;
using System.Linq;

namespace MaterialDemo.Service.Login
{
    public class Login : ILogin
    {
        #region 构造函数注入   
        private readonly ILogger<Login> _logger;
        private readonly DbContext _dbContext;
        public Login(ILogger<Login> logger, DbContext dbContext)
        {
            _logger = logger;
            _dbContext = dbContext;

        }
        #endregion
        public UserOutput Logins(string userId, string pwd)
        {
            _logger.LogWarning("开始登陆！");
            string MD5Pwd = MD5Helper.EncryptString(pwd);
            return (from a in _dbContext.Set<UserInfo>().Where(u => u.UserId == userId && u.PassWord == MD5Pwd && u.DelFlag == 0)
                    select new UserOutput
                    {
                        UserId = a.UserId,
                        UserName = a.UserName,
                    }).FirstOrDefault();

        }
    }
}
